package com.wanshi.cloud.controller;


import com.wanshi.cloud.entity.Orders;
import com.wanshi.cloud.service.IOrderService;
import com.wanshi.cloud.utils.base.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 顽石教育-www.wanshi.com
 * @since 2021-09-02
 */
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private IOrderService orderService;

    //1 根据userId查询用户
    @GetMapping("/user/{userId}")
    public Result findByUserId(@PathVariable Integer userId){
        List<Orders> list = orderService.findByUserId(userId);
        return Result.ok(list);

    }

    //2 根据订单id查询
    @GetMapping("/{id}")
    public Result findById(@PathVariable("id") String id){

        Orders order = orderService.findById(id);

        return Result.ok(order);
    }

    //3 根据订单id查询商品id
    @PostMapping("/product/{id}")
    public Orders findProductById(@PathVariable("id") String id){

        return orderService.findProductById(id);

    }
}
